﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>使用userData保存文本内容</title>
    <style>
        .userData {
            behavior: url(#default#userdata);
        }
    </style>
    <script>
        function saveInput() {
            var oPersist = Form1.myText;
            oPersist.setAttribute("sPersist", oPersist.value);
            oPersist.save("oXMLBranch");
        }
        function loadInput() {
            var oPersist = Form1.myText;
            oPersist.load("oXMLBranch");                         //载入在名为oXMLBranch的UserData存储区
            oPersist.value = oPersist.getAttribute("sPersist");    //将sPersist属性赋值给oPersist.value
        }
    </script>
</head>
<body>
    <form id="Form1">
        <input class="userData" type="text" id="myText" />
        <input type="button" value="加载" onclick="loadInput()" />
        <input type="button" value="保存" onclick="saveInput()" />
    </form>
</body>
</html>